<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/vendor/bootstrap/css/bootstrap.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/assets/vendor/font-awesome/css/font-awesome.min.css">
    <!-- Custom Font Icons CSS-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/font.css">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/custom.css">
    <title>会议系统</title>

</head>
<body>
<%@include file="../publicjsp/head.jsp" %>

<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <nav id="sidebar">
        <!-- Sidebar Header-->
        <!-- Sidebar Header-->
        <%@include file="../publicjsp/sideHead.jsp" %>
        <!-- Sidebar Navidation Menus--><span class="heading">Main</span>
        <%@include file="../publicjsp/sidebar.jsp" %>

    </nav>
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">会议系统</h2>
            </div>
        </div>

        <section class="no-padding-bottom">

            <div class="list-group myList">
                <!--搜索文章的条件-->
                <div class="myTitle">
                    <form class="form-inline" action="${pageContext.request.contextPath}/meet/list" method="post">
                        <div class="form-group">
                            <label for="inlineFormInput" class="sr-only">Name</label>
                            <c:if test="${searchName == null}">
                                <input id="inlineFormInput" name="searchName" type="text" placeholder="按标题名字查找"
                                       class="mr-sm-3 form-control">
                            </c:if>
                            <c:if test="${searchName != null}">
                                <input id="inlineFormInput" name="searchName" type="text" value="${searchName}"
                                       placeholder="按标题名字查找"
                                       class="mr-sm-3 form-control">
                            </c:if>
                        </div>
                        <div class="form-group">
                            <input type="submit" value="查询" class="btn btn-primary">
                        </div>
                        <!--选择部门-->
                        <div class="form-group">
                            <select name="deptName" class="form-control">
                                <c:if test="${deptName == null || deptName == ''}">
                                    <option value="">请选择部门</option>
                                </c:if>
                                <c:if test="${deptName != null && deptName != ''}">
                                    <option value="${deptName}">${deptName}</option>
                                    <option value="">请选择部门</option>
                                </c:if>
                                <c:forEach items="${deptList}" var="dept">
                                    <c:if test="${deptName != dept.name}">
                                        <option value="${dept.name}">${dept.name}</option>
                                    </c:if>
                                </c:forEach>
                            </select>
                        </div>
                    </form>
                    <input id="addMeet" type="button" value="发布会议" class="btn btn-primary">
                </div>

                <ul>
                    <c:forEach items="${conferenceList}" var="conference">
                        <li class="list-group-item">
                            <div style="float: right;">
                                <c:if test="${conference.status == '0'}">
                                    <span><strong>状态：</strong>未开始</span>
                                </c:if>
                                <c:if test="${conference.status == '1'}">
                                    <span><strong>状态：</strong>进行中</span>
                                </c:if>
                                <c:if test="${conference.status == '2'}">
                                    <span><strong>状态：</strong>已结束</span>
                                </c:if>
                            </div>
                            <a href="${pageContext.request.contextPath}/meet/meetInfo?mId=${conference.id}">${conference.title}</a>
                            <p class="h6"><strong>部门：</strong>${conference.deptName}</p>
                            <p class="h6"><strong>日期：</strong>${conference.publishDate}</p>
                            <p style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis">${conference.content}</p>
                        </li>
                    </c:forEach>
                </ul>

                <nav class="text-center" aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <a id="pre" href="#" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <c:forEach varStatus="vs" begin="${startPage}" end="${endPage}" step="1">
                            <c:if test="${vs.index == currentPage}">
                                <li><a onclick="clickPage(${vs.index})" class="act" href="#">${vs.index}</a></li>
                            </c:if>
                            <c:if test="${vs.index != currentPage}">
                                <li><a onclick="clickPage(${vs.index})" href="#">${vs.index}</a>
                                </li>
                            </c:if>
                        </c:forEach>
                        <li>
                            <a id="next" href="#" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </section>

        <%@include file="../publicjsp/footer.jsp" %>
    </div>
</div>

<!-- JavaScript files-->
<script src="${pageContext.request.contextPath}/assets/vendor/jquery/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/vendor/popper.js/umd/popper.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/vendor/jquery.cookie/jquery.cookie.js"></script>
<script src="${pageContext.request.contextPath}/assets/vendor/chart.js/Chart.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/vendor/jquery-validation/jquery.validate.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/charts-home.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/front.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/custom.js"></script>
</body>
<script>

    var pre = document.getElementById("pre");
    pre.onclick = function (ev) {
        var page = '${startPage -1}';
        if (page === '0') {
            alert("已经没有上一页了");
            return;
        }
        console.log("跳转上一个页码是：" + page);
        var searchName = '${searchName}';
        if (searchName === null || searchName === '') {
            window.location.href = '${pageContext.request.contextPath}/article/getArticles?page=' + page;
        } else {
            window.location.href = '${pageContext.request.contextPath}/article/getArticles?page=' + page + '&searchName=' + searchName;
        }
    };


    var next = document.getElementById("next");
    next.onclick = function (ev) {
        var totalPage = parseInt('${totalPage}');
        var page = '${startPage + pageCount}';
        if (page > totalPage) {
            alert("已经没有下一页了");
            return;
        }
        console.log("跳转下一个页码是：" + page);
        var searchName = '${searchName}';
        if (searchName === null || searchName === '') {
            window.location.href = '${pageContext.request.contextPath}/article/getArticles?page=' + page;
        } else {
            window.location.href = '${pageContext.request.contextPath}/article/getArticles?page=' + page + '&searchName=' + searchName;
        }
    };

    function clickPage(page) {
        console.log(page);
        var searchName = '${searchName}';
        if (searchName === null || searchName === '') {
            window.location.href = '${pageContext.request.contextPath}/article/getArticles?page=' + page;
        } else {
            window.location.href = '${pageContext.request.contextPath}/article/getArticles?page=' + page + '&searchName=' + searchName;
        }
    }
</script>
</html>